<style>
        .panel-header, .panel-body {
            border-width: 0px;
        }

        .datagrid, .combo-p {
            border: solid 1px #D4D4D4;
        }

        .panel-title {
            cursor: pointer
        }

        .inlineblock {
            margin-top: 10px;
        }

        .inlineblock div {
            display: inline-block;
        }

        .inlineblock div label {
            display: inline-block;
            top: 5px;
        }

        .newform {
            width: 70%;
        }

        .editform {
            width: 70%;
        }

        .searchClass {
            /* 		margin-left: 5%;
                     */		margin-top: 1%;
        }

        .searchClass label {        width: 9%;
            font-weight: bold;
            text-align: center;
        }

        #Search {
            float: right;
            margin-right: 4%;
            width: 14%;
        }
        .file {
            position: relative;
            display: inline-block;
            background: #D0EEFF;
            border: 1px solid #99D3F5;
            border-radius: 4px;
            padding: 4px 12px;
            overflow: hidden;
            color: #1E88C7;
            text-decoration: none;
            text-indent: 0;
            line-height: 20px;
        }
        .file input {
            position: absolute;
            font-size: 100px;
            right: 0;
            top: 0;
            opacity: 0;
        }
        .file:hover {
            background: #AADFFD;
            border-color: #78C3F3;
            color: #004974;
            text-decoration: none;
        }
    </style>
        <div class="row">
            <div id="breadcrumb" class="col-xs-12" style="margin-bottom: 10px">
                <a href="#" class="show-sidebar"> <i class="fa fa-bars"></i>
                </a>
                <ol class="breadcrumb pull-left">
                    <li><a href="#">城市行为管理</a></li>
                    <li><a href="#">行为管理</a></li>
                </ol>
            </div>
        </div>
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-header">
                        <div class="box-name">
                            <i class="fa fa-clipboard"></i> <span>行为管理</span>
                        </div>
                        <div class="box-icons">
                            <a class="collapse-link"> <i class="fa fa-chevron-up"></i>
                            </a> <a class="expand-link"> <i class="fa fa-expand"></i>
                        </a> <a class="close-link"> <i class="fa fa-times"></i>
                        </a>
                        </div>
                        <div class="no-move"></div>
                    </div>
                    <div class="box-content table-responsive" style="padding-top: 15px">

                        <div class="panel panel-default" style="border: 1px solid #CCC; height: auto;">
                            <div class="panel-heading" role="tab" id="headingOne">
                                <h4 class="panel-title" data-target="#collapseForAdd">
                                    <span id="back" style="color: cornflowerblue;">>>返回</span> <span class="fa fa-chevron-down" style="float: right"></span>
                                </h4>
                            </div>

                            <div id="collapseForAdd" class="panel-collapse collapse in" role="tabpanel"
                                 aria-labelledby="headingOne">
                                <div class="panel-body">
                                    <div class="container-fluid" style="margin-top: 10px;">
                                        <!--操作-->
                                        <div id="operationpanel" class="col-xs-12">
                                            <div class="col-xs-12 btn-menu-top-minus" style="margin-top:5px;">
                                                <button class="btn btn-primary btn-sm addbook" data-toggle="modal" data-target="#exampleModal">
                                                    <i class="fa fa-file-o"></i>添加行为管理
                                                </button>
                                                <!--<button class="btn btn-primary btn-sm editbook" data-toggle="modal" data-target="#exampleModal">-->
                                                <!--<i class="fa fa-file-o"></i>修改生活公众信息-->
                                                <!--&lt;!&ndash;<a href="{:U('Life/addLife')}"></a>&ndash;&gt;-->
                                                <!--</button>-->
                                            </div>
                                        </div>

                                    </div>
                                </div>
                            </div>
                        </div>

                        <!--主信息面板 S-->
                        <div class="panel panel-default" style="border: 1px solid #CCC;">
                            <div id="collapseForCourseTable" class="panel-collapse collapse in" role="tabpanel"
                                 aria-labelledby="headingTwo">
                                <div class="panel-body" style="overflow: hidden;">
                                    <!--搜索区域-->
                                    <div class="searchClass row">
                                        <div class="col-xs-12">
                                            <input class="SearchForm form-control" type="hidden" value="{$behavior_id}" id="behavior_id"/>
                                        </div>
                                    </div>
                                    <!--<br/>-->
                                    <!--<button id="Search" class="btn btn-primary btn-xs" style="height: 30px;margin-left: 30px">-->
                                        <!--<i class="fa fa-search"></i>&nbsp;&nbsp;搜索-->
                                    <!--</button>-->
                                    <!--<button id="Reset" class="btn btn-primary btn-sm" style="width:120px;float: right;">-->
                                        <!--清空查询条件-->
                                    <!--</button>-->
                                </div>
                                <table id="datatable_noticeinfo" data-size="15">

                                </table>
                                <div id ="pp" style = "background:#efefef; border:1px solid #ccc;width:100%" > </div>
                            </div>
                        </div>
                        <!--主信息面板 E-->
                    </div>
                </div>
            </div>
        </div>
<script>
    /**
     * 获得搜索参数
     * @param params
     * @returns {Object}
     */
    function getSearchParams(params) {
        var searchParams = new Object();
        if (params != undefined) {
            searchParams = params;
        }
        $('.SearchForm').each(function () {
            var param = $(this).val().trim();
            if (param == undefined)
                param = '';
            searchParams[$(this).attr('id')] = param;
        });
        return searchParams;
    }

    $(function () {
        var cellwidth = ($(".box-content.table-responsive").width() - 55) / 11;
        var psval = $('#datatable_noticeinfo').attr('data-size');
        if (psval == undefined || psval == "") {
            psval = 10;
        }
        //页面首次加载获取数据
        $('#datatable_noticeinfo').datagrid({
            striped: true,
            remoteSort: false,
//            idField: 'city_id',
            collapsible: true,
            fit: false,
            url: 'admin/City/behavior',//数据源路径
            loadMsg: '请等待数据载入....',
            pagination: true,
            rownumbers: true,
            fitColumns: true,
            nowrap:false,
            singleSelect: true,
            pageSize: psval,
            pageList: [psval, psval * 2, psval * 3, psval * 4, psval * 5],
            columns: [[
                {
                    field: 'behavior_name',
                    title: '行为名称',
                    align: 'center',
                    width: cellwidth,
                    sortable: true
                }, {
                    field: 'behavior_img',
                    title: '行为图标',
                    align: 'center',
                    width: cellwidth,
                    sortable: true,
                    formatter:function(value,row,index){
                        if(value!=''){
                            return "<img src='"+row.behavior_img+"' style='width:100px;height:100px'>";
                        }
                    }
                }, {
                    field: 'behavior_pic',
                    title: '城市行为图',
                    align: 'center',
                    width: cellwidth,
                    sortable: true,
                    formatter:function(value,row,index){
                        if(value!=''){
                            return "<img src='"+row.behavior_pic+"' style='width:100px;height:100px'>";
                        }
                    }
                }
                , {
                    field: 'behavior_id',
                    title: '操作',
                    align: 'center',
                    width: cellwidth,
                    sortable: true,
                    formatter:function(value,row,index){
                        var html ='';
                        html +="<a onclick='deleteInfo(this);' style='color:brown;margin-left:5px' name='"+value+"' href='JavaScript:;'>删除</a>";
                        html +="<a onclick='updateInfo(this);' style='color:darkslateblue;margin-left:5px' name='"+value+"' href='JavaScript:;'>修改</a>";
                        return html;
                    }
                }
            ]],
            onBeforeLoad: function (param) {
                param = getSearchParams(param);
            },
        });

        //搜索
        $('#Search').click(function () {
            $('#datatable_noticeinfo').datagrid('reload');
        });
        //清空搜索条件
        $("#Reset").click(function() {
            $('.SearchForm').val('');
        });

        //添加
        $('.addbook').click(function () {
            var content = "";
          var  behavior_id = $('#behavior_id').val();
            $.ajax({
                url: 'admin/City/addB',
                type: 'POST',
                data:{'behavior_id':behavior_id},
                dataType: 'HTML',//返回的数据类型
                success: function (updatemodalhtml) {
                    content = updatemodalhtml;
                    //弹出添加框
                    $.TeachDialog({
                        title: '新增城市行为',
                        content: content,
                        showCloseButton: true,
                        largeSize: true,
                        showCloseButtonName: '关闭',
                        otherButtons: ['保存'],
                        otherButtonStyles: ['btn-primary'],
                        clickButton: function (sender, modal, index) {
                            var formData = new FormData($("#updateForm" )[0]);
                            $.ajax({
                                url: 'admin/City/addInsert',
                                data: formData,
                                type: 'POST',
                                dataType: 'JSON',
                                async: false,
                                cache: false,
                                contentType: false,
                                processData: false,
                                success: function (returnData) {
                                    if (returnData.status == 0) {
                                        layer.open({
                                            content: returnData.msg
                                        });
                                    } else {
                                        modal.modal('hide');
                                        layer.open({
                                            content: returnData.msg
                                        });
                                        $('#datatable_noticeinfo').datagrid('reload');
                                    }
                                },
                                error: function () {
                                    $.TeachDialog({
                                        content: '系统异常，请联系管理员',
                                    });
                                },

                            });

                        },
                    });
                },
                error: function () {
                    $.TeachDialog({
                        content: '系统异常，请联系管理员',
                    });
                    return;
                }
            });
        });
    });

    /**
     * 删除公共信息
     */
    function deleteInfo(c) {
        var cid = c.name;
        if(confirm('确认此城市信息吗？')){
            $.ajax({
                url: 'admin/City/deleteBehavior',
                data: 'cid=' + cid,
                type: 'POST',
                dataType: 'JSON',
                success: function (returnData) {
                    if (returnData.status == 0) {
                        $.TeachDialog({
                            content: returnData.msg
                        });
                    } else {
                        $.TeachDialog({
                            content: returnData.msg,
                            showCloseButton: false,
                        });
                        $('#datatable_noticeinfo').datagrid('reload');

                    }
                },
                error: function () {
                    $.TeachDialog({
                        content: '系统异常，请联系管理员',
                    });
                },

            });
        }
    }

    //修改
    function updateInfo(c) {
        var content = "";
        var city_id = c.name;
        $.ajax({
            url: 'admin/City/updateB',
            data: "nid=" + city_id,
            type: 'POST',
            dataType: 'HTML',//返回的数据类型
            success: function (updatemodalhtml) {
                content = updatemodalhtml;
                //弹出修改框
                $.TeachDialog({
                    title: '修改城市行为',
                    content: content,
                    showCloseButton: true,
                    largeSize: true,
                    showCloseButtonName: '关闭',
                    otherButtons: ['保存'],
                    otherButtonStyles: ['btn-primary'],
                    clickButton: function (sender, modal, index) {
                        var formData = new FormData($("#updateForm" )[0]);
                        $.ajax({
                            url: 'admin/City/updateBehavior',
                            data: formData,
                            type: 'POST',
                            dataType: 'JSON',
                            async: false,
                            cache: false,
                            contentType: false,
                            processData: false,
                            success: function (returnData) {
                                if (returnData.status == 0) {
                                    layer.open({
                                        content: returnData.msg
                                    });
                                } else {
                                    modal.modal('hide');
                                    layer.open({
                                        content: returnData.msg
                                    });
                                    $('#datatable_noticeinfo').datagrid('reload');
                                }
                            },
                            error: function () {
                                $.TeachDialog({
                                    content: '系统异常，请联系管理员'
                                });
                            },

                        });

                    },
                });
            },
            error: function () {
                $.TeachDialog({
                    content: '系统异常，请联系管理员'
                });
                return;
            }
        });
    }

    $('#back').click(function () {
        window.location.href = "admin#city";
        setTimeout(function () {
            location.reload();
        },500);

    });
</script>
